#include <iostream>
#include <vector>
using namespace std;

struct TreeNode{
  int val;
  TreeNode* left;
  TreeNode* right;
  TreeNode(int x):val(x),left(NULL),right(NULL){}
};

void process(TreeNode *pRoot,unsigned int iNowLevel,vector<long long>& aLevelSum,vector<int>& aNodeCounte)
{
  if(pRoot == nullptr)
    {
      return;
    }
  if((iNowLevel+1 >= aLevelSum.size()) || (iNowLevel+1 >= aNodeCounte.size()))
    {
      aLevelSum.resize(iNowLevel+1);
      aNodeCounte.resize(iNowLevel+1);
    }
  aLevelSum[iNowLevel]+=pRoot->val;
  ++aNodeCounte[iNowLevel];
  process(pRoot->left,iNowLevel+1,aLevelSum,aNodeCounte);
  process(pRoot->right,iNowLevel+1,aLevelSum,aNodeCounte);
}

vector<double> averageOfLevels(TreeNode *root)
{
  vector<double> res;
  vector<long long> aTempSum;
  vector<int> aTempNode;
  process(root,0,aTempSum,aTempNode);
  res.resize(aTempSum.size());
  for(unsigned int i=0;i<aTempSum.size();++i)
    {
      res[i]=(static_cast<double>(aTempSum[i]))/aTempNode[i];
    }
  return res;
}

int main()
{
  
}
